package org.wanho.txy.ems.vo;

import lombok.Data;
import org.wanho.txy.ems.constant.ResponseStatusConstant;

import java.io.Serializable;

/**
 * Author：汤小洋
 * Date：2023-04-28 15:21
 * Description：Ajax响应对象
 */
@Data
public class ResponseResult implements Serializable {
    //响应状态码
    private int code;
    //响应消息
    private String msg;
    //返回数据
    private Object data;
    // 数据条件
    private int count;

    /**
     * 返回表示成功的ResponseResult实例
     * @return
     */
    public static ResponseResult success(){
        ResponseResult result = new ResponseResult();
        result.setCode(ResponseStatusConstant.SUCCESS);
        result.setMsg("success");
        return result;
    }

    public static ResponseResult success(Object data,int count){
        ResponseResult result = new ResponseResult();
        result.setCode(ResponseStatusConstant.SUCCESS);
        result.setMsg("success");
        result.setData(data);
        result.setCount(count);
        return result;
    }

    public static ResponseResult success(Object data){
        ResponseResult result = new ResponseResult();
        result.setCode(ResponseStatusConstant.SUCCESS);
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    /**
     * 返回表示失败的ResponseResult实例
     * @return
     */
    public static ResponseResult fail(String message){
        ResponseResult result = new ResponseResult();
        result.setCode(ResponseStatusConstant.FAIL);
        result.setMsg(message);
        return result;
    }
}
